home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / cache.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  2.0 KB  |  93 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef _SYNTH_CACHE_H
  24. #define _SYNTH_CACHE_H
  25.  
  26. #include <time.h>
  27. #include <list>
  28. #include <string>
  29. #include "startupmanager.h"
  30. #include "arts_export.h"
  31.  
  32. /*
  33.  * BC - Status (2002-03-08): Cache, CachedObject
  34.  *
  35.  * At the current point in time, there are NO GUARANTEES, so only use this
  36.  * in apps part of official KDE releases (such as kdemultimedia apps), which
  37.  * know what is happening here.
  38.  */
  39.  
  40. namespace Arts {
  41. class Cache;
  42.  
  43. class ARTS_EXPORT CachedObject
  44. {
  45. private:
  46.     std::string _object_key;
  47.     int _ref_cnt;
  48.     time_t _lastAccess;
  49.  
  50. protected:
  51.     void setKey(std::string key);
  52.  
  53. public:
  54.     std::string getKey();
  55.  
  56.     time_t lastAccess();
  57.  
  58.     void decRef();
  59.     void incRef();
  60.     int refCnt();
  61.  
  62.     virtual bool isValid();
  63.     virtual int memoryUsage() = 0;
  64.  
  65.     CachedObject(Cache *cache);
  66.     virtual ~CachedObject();
  67. };
  68.  
  69. class ARTS_EXPORT Cache
  70. {
  71. protected:
  72.     std::list<CachedObject *> objects;
  73.     Cache();
  74.     ~Cache();
  75.  
  76.     static Cache *_instance;
  77.  
  78. public:
  79.     static Cache *the();
  80.     static void shutdown();
  81.  
  82.     static long memused;
  83.  
  84.     CachedObject *get(std::string key);
  85.     void add(CachedObject *object);
  86.  
  87.     // garbage collection; returns amount of memory used (after cleaning)
  88.     long cleanUp(long cacheLimit);
  89. };
  90.  
  91. }
  92. #endif
  93.